package org.javaboy.vhr.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    private static SimpleDateFormat year = new SimpleDateFormat("yyyy");
    private static SimpleDateFormat month = new SimpleDateFormat("MM");
    private static DecimalFormat decimalFormat = new DecimalFormat("##.00");

    public static double getMonthTotal(Date startDate, Date endDate){
        // 获取两个日期的年数
        String startYear = year.format(startDate);
        String endYear = year.format(endDate);
        Double yearMonthTotal = 12*(Double.parseDouble(endYear)-Double.parseDouble(startYear));
        // 获取两个日期的年数
        String startMonth = month.format(startDate);
        String endMonth = month.format(endDate);
        Double monthTotal = Double.parseDouble(endMonth)-Double.parseDouble(startMonth);
        String format = decimalFormat.format((yearMonthTotal + monthTotal) / 12);
        return Double.parseDouble(format);
    }
}
